<template>
  <div class="tab-control">
    <div class="tab-control-item" v-for="(item, index) in titles" :key="index" :class="{ active: currentIndex === index }"
      @click="ItemClick(index)">
      <span>{{ item }}</span>
    </div>
  </div>
</template>

<script>
export default {
  name: "TabControl",
  props: {
    titles: {
      // 先父传子 传输数据 然后进行展示操作
      type: Array,
      default() {
        return []
      }
    }
  },
  data() {
    // 封装思想
    return {
      currentIndex: 0
    }
  },
  methods: {
    // 子组件点击事件的操作 传输子组件的index 用来保存数据的操作
    ItemClick(index, $event) {
      this.currentIndex = index
      this.$emit('tabclick', index)
    }
  },
}
</script>

<style scoped>
.tab-control {
  display: flex;
  text-align: center;
  font-size: 15px;
  height: 40px;
  line-height: 40px;
  background-color: #ffffff;
  z-index: 1;
}

.tab-control-item {
  flex: 1;
}

.active {
  color: var(--color-high-text);
}

.active span {
  border-bottom: 2px solid var(--color-tint);
  padding: 5px;
}
</style>
